﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using UavForm;

using static System.Windows.Forms.VisualStyles.VisualStyleElement;

namespace UavForm
{
    public partial class Professional : Form
    {
        public Professional()
        {
            InitializeComponent();
        }

        private void btnExpertQuery_Click(object sender, EventArgs e)
        {
        
            string userInputSql = textBox2.Text.Trim();

            if (userInputSql.IndexOf("update") >= 0 || userInputSql.IndexOf("insert") >= 0 || userInputSql.IndexOf("delete") >= 0)
            {
                MessageBox.Show("Add, delete, or modify operations are prohibited!");
                return;
            }
            try
            {
                DataSet resultSet = dbHelper.FetchData(userInputSql);
                professionalData.DataSource = resultSet;
                professionalData.DataMember = resultSet.Tables[0].TableName;
                professionalData.RowHeadersVisible = false;
            }
            catch (Exception ex)
            {
                MessageBox.Show($"Query execution failed：{ex.Message}");
            }
        }
        public DbHelper dbHelper;
        private void Professional_Load(object sender, EventArgs e)
        {
            dbHelper =new DbHelper();
        }

        private void button6_Click(object sender, EventArgs e)
        {
            textBox2.Clear();
        }

    }
}
